define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'gx_history/index' + location.search,
                    add_url: 'gx_history/add',
                    edit_url: 'gx_history/edit',
                    del_url: 'gx_history/del',
                    multi_url: 'gx_history/multi',
                    table: 'gx_history',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.nickname', title: __('User.nickname')},
                        {field: 'user.mobile', title: __('User.mobile')},
                        {field: 'user.money', title: __('User.money'), operate:'BETWEEN'},
                        {field: 'user.score', title: __('User.score'), operate:'BETWEEN'},
                        {field: 'coin_id', title: __('Coin_id'), searchList: {"money":__('Coin_id money'),"score":__('Coin_id score')}, formatter: Table.api.formatter.normal},
                        {field: 'amount', title: __('Amount'), operate:'BETWEEN'},
                        {field: 'before_balance', title: __('Before_balance'), operate:'BETWEEN'},
                        {field: 'after_balance', title: __('After_balance'), operate:'BETWEEN'},
                        {field: 'change_type', title: __('Change_type'),
                            searchList: {"1000":__('Change_type 1000'),"2000":__('Change_type 2000'),"2010":__('Change_type 2010')
                                ,"2020":__('Change_type 2020'),"2030":__('Change_type 2030'),"3000":__('Change_type 3000')
                                ,"4000":__('Change_type 4000'),"4010":__('Change_type 4010'),"4020":__('Change_type 4020')
                                ,"4030":__('Change_type 4030'),"4040":__('Change_type 4040')
                                ,"5000":__('Change_type 5000'),"5010":__('Change_type 5010'),"2040":__('Change_type 2040')},formatter: Table.api.formatter.status},
                        {field: 'remark', title: __('Remark')},
                        {field: 'created_at', title: __('Created_at'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});